package com.sdp.irrigation.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.sdp.core.bizc.redis.RedisUtil;
import com.sdp.core.bizc.threadLocal.ContextManager;
import com.sdp.core.bizc.utils.CoreConstantsEnum;
import com.sdp.right.entity.SysEmp;
import com.sdp.right.service.RightExtService;

@Component
public class CurrentLoginEmp {
	
	@Autowired
	private RedisUtil redisUtil;
	
	@Autowired
	private RightExtService rightExtService;
	
	public JSONObject getCurrentLoginInfo(){	
		Object redisEmp = redisUtil.getMap(SysEmp.class, ContextManager.getContextData(CoreConstantsEnum.token中账号的属性名.getCode()).toString());
		if(redisEmp == null || "{}".equals(redisEmp.toString())) {
			SysEmp emp = rightExtService.getCurrentEmpInfo();
			redisUtil.setMap(SysEmp.class, emp.getAccountNo(), emp);
			redisEmp = emp;
		}
		return JSONObject.parseObject(JSON.toJSONString(redisEmp,SerializerFeature.WriteMapNullValue));
	}

}
